Skip to content

perf(ios): read keyboard status from one keyboard snapshot - #4642

Merged
thymikee merged 1 commit into
mainfrom
t3/speed-ios-keyboard-status
Nov 17, 2026
Merged

thymikee merged 1 commit into
mainfrom
t3/speed-ios-keyboard-status

Conversation

@thymikee

@thymikee thymikee commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Closes #4641

What

keyboard status on iOS read each keyboard key's label and frame as its own XCTest element query (two resolves per key, about 35 ms each across the keyboard's process boundary). On a 40-key English keyboard that made the runner command take about 1.3 s. The status read now takes one snapshot() of the keyboard element. That snapshot carries the keyboard's visibility, its frame, and every key's and button's wording and frame, so the whole read is one round trip.

The output contract (visible, returnKey, returnKeyLabel) and the return-key rule in RunnerKeyboardStatus are unchanged. The shared return-key lookup that keyboard enter and dismiss use (findKeyboardReturnControl, tapKeyboardDismissControl) is untouched. The diff is keyboardStatus and observedKeyboardKeys in RunnerTests+Keyboard.swift, one unit test, and one comment name in navigation/runtime.ts.

Where the time went

Before, one keyboard status --debug on main, from the request ndjson and the runner log:

Stage Before After
daemon request total 1652 ms 291 ms
resolve_target_device (explicit --udid, xcrun simctl list) 328 ms 256 ms
runner keyboardStatus command 1306 ms 23 ms
XCTest queries inside the runner command exists + frame, 2 bulk allElementsBoundByIndex, then about 80 per-element label / frame resolves one Find the Keyboard snapshot

No waitForIdle, settle or repeated tree read was involved. The command already ran with withBoundedInteractionIdleTimeoutIfSupported(.bothSkipped). The cost was only the per-element round trips.

Timings

iPhone 17e simulator, iOS 27.0, warm daemon, keyboard up on the Wallet sign-up email field (explore-example-wallet://auth/sign-up). Wall clock per CLI call including node start, n=8 each, ms. Each run used its own private AGENT_DEVICE_STATE_DIR.

Call Main (before), --udid Branch, --udid Branch, session only
keyboard status median 1612 (1498-2185) 476 (430-624) 232 (227-510)
snapshot median 309 (298-551) 320 (288-408) 300 (271-421)

Raw samples, main --udid, status: 1606 1498 1845 1618 1514 2185 1884 1604. Snapshot: 551 378 309 309 304 298 309 530.
Branch --udid, status: 441 580 432 472 624 588 430 480. Snapshot: 302 295 330 310 357 408 376 288.
Branch session only, status: 510 233 240 227 228 230 231 242. Snapshot: 271 282 299 333 421 353 286 302.

The remaining gap to snapshot

With the session alone selecting the device, keyboard status costs about 0.23 s, at or below snapshot. With an explicit --udid on every call (as the T3 device wrapper passes), it is about 0.16 s over snapshot. The cause is outside the status path. resolveCommandDevice treats an explicit device selector as a fresh selection and re-reads the simulator inventory (resolve_target_device, 256 ms, cacheHit:false). snapshot goes through resolveSessionDevice and skips it. That cost applies to every command that resolves its device through resolveCommandDevice, so I left it for its own change and kept this PR on the status read path.

Output identical before and after

keyboard status --json on main and on this branch, for each state:

State Output (both)
name field visible: true, returnKey: next, returnKeyLabel: next
email field visible: true, returnKey: next, returnKeyLabel: next
password field visible: true, returnKey: done, returnKeyLabel: done
keyboard hidden (after keyboard enter on the password field) visible: false

Verification

  • Device: iPhone 17e simulator, iOS 27.0, F25C7515-D67E-4838-BEAC-0AD08DB056EC.
  • Measured source: main 1cb2f242ae (before) and this branch with the same runner change at the head before the unit test and formatting pass was added. The runner was rebuilt with pnpm build:xcuitest:ios.
  • New unit test: testObservedKeyboardKeysReadsKeysThenButtonsFromOneKeyboardSnapshot (iOS only, nightly lane). It checks nested descendants, keys before buttons, the whitespace-only space bar kept, and label-less or non-key elements dropped.
  • pnpm check:xctest-selection passes locally. Per the worktree rules, CI validates the rest.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

keyboard status read each key's label and frame as its own XCTest element
query, about 35 ms per key, which made the runner command take 1.3 s on a
40-key keyboard. One snapshot of the keyboard carries its visibility, frame,
and every key's wording and frame, so the read is one round trip (23 ms).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.37 MB 6.37 MB +329 B
Package (unpacked) 6.37 MB 6.37 MB +329 B
Package (download) 1.93 MB 1.93 MB +52 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.3 ms 19.4 ms -0.8 ms
CLI --help 44.2 ms 43.6 ms -0.6 ms

@thymikee

Copy link
Copy Markdown
Member Author

The PR is ready from this review at d0a94e0, and I found nothing that needs a change before merge. 19 of 20 checks pass and one review check is still queued. There are no conflicts. Not blocking, and you can take or leave these: reuse snapshotDescendants(of:) in observedKeyboardKeys(in:) instead of the second traversal (RunnerTests+Keyboard.swift#L238); collapse the dead off-iOS #else branch of keyboardStatus or note in its doc that off-iOS answers hidden; run keyboard status --json once on d0a94e0 on the same simulator, ideally with an iPad or number-pad field, since the live table predates the unit test and formatting pass and covers only English iPhone layouts; split a pure keyboardStatus(from snapshot:) so the hidden-on-nil and hidden-on-empty-frame rules get a unit test; and file a follow-up issue for the ~0.16 s explicit-selector re-resolve and link it in the PR body.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 17, 2026
@thymikee
thymikee merged commit b2d32eb into main Nov 17, 2026
19 of 20 checks passed
@thymikee
thymikee deleted the t3/speed-ios-keyboard-status branch November 17, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS keyboard status takes ~1.4 s, about 5x a snapshot

1 participant